import { applyMiddleware, createStore, compose } from 'redux';
import { persistStore, autoRehydrate } from 'redux-persist';
import { AsyncStorage } from 'react-native';
import middleware from './middleware';
import rootReducer from './rootReducer';
// import immutableTransform from 'redux-persist-transform-immutable';
import { KEY_PREFIX } from '../constants'

const enhancers = [
  applyMiddleware(...middleware)
];

let composeEnhancers = compose;

const enhancer = composeEnhancers(...enhancers);

// create the store
const store = createStore(
  rootReducer,
  enhancer,
  autoRehydrate(),
)

// immutable persitis data of Record transparent object with immutable
// let records = [].concat()

persistStore(store, {
  storage: AsyncStorage,
  keyPrefix: KEY_PREFIX
}).purge()

export default store;
